package de.mwa.jersey.todo.maintenance;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Helper class for HSA Server. This class provides logging functionality.
 * 
 * @author Denis Schuldt
 * 
 */
public class LogMgmt {

	/**
	 * Use this function to write something to the log. a timestamp is prefixed.
	 * 
	 * @param text
	 *            the text you want to write to the log
	 * @throws IOException
	 */
	public void writeLog(String text) throws IOException {
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();
		System.out.println(dateFormat.format(date));

		File log = new File(Setup.MaintenanceDirectory + "Log.txt");
		log.createNewFile();
		FileWriter writer = new FileWriter(log, true);
		writer.write(dateFormat.format(date) + " - " + text
				+ System.getProperty("line.separator"));
		writer.close();
	}
}
